//
//  LeftViewController.m
//  UI_Custom
//
//  Created by yutao on 15/2/12.
//  Copyright (c) 2015年 yutao. All rights reserved.
//

#import "LeftViewController.h"
#import "DDMenuController.h"
#import "AppDelegate.h"

#import "TBCReadingViewController.h"
#import "TBCVideoViewController.h"
#import "TBCRadioViewController.h"
#import "TBCWeatherViewController.h"
#import "TBCSettingViewController.h"

@interface LeftViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation LeftViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *imageViewBG = [[UIImageView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    imageViewBG.image = [UIImage imageNamed:@"DrawerBg@2x"];
    [self.view addSubview:imageViewBG];
    
    BaseTableView *tableView = [[BaseTableView alloc] initWithFrame:CGRectMake(0, HEIGHT - 5 * 70, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.scrollEnabled = NO;
    [self.view addSubview:tableView];

    
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    return 5;
}

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *CellIdentifier = @"CellIdentifier";
    BaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if(!cell) {
        cell = [[BaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }
    
    cell.imageView.frame = CGRectMake(0, 0, 40, 40);

    if (indexPath.row == 0) {
        cell.textLabel.text = @"电台";
        cell.imageView.image = [UIImage imageNamed:@"Radio40*40@2x"];

    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"视频";
        cell.imageView.image = [UIImage imageNamed:@"Video40*40@2x"];
        
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"阅读";
        cell.imageView.image = [UIImage imageNamed:@"Reading40*40@2x"];
        
    }
    if (indexPath.row == 3) {
        cell.textLabel.text = @"天气";
        cell.imageView.image = [UIImage imageNamed:@"Weather40*40@2x"];
        
    }
    if (indexPath.row == 4) {
        cell.imageView.image = [UIImage imageNamed:@"Settings40*40@2x"];
        cell.textLabel.text = @"设置";
        
    }
   
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 70;
}


#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    DDMenuController *menuController = (DDMenuController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).menuController;
    
    // 设置根视图
    if (indexPath.row == 0) {
        
        TBCRadioViewController *controller = [[TBCRadioViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"电台"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];

    }
     
    
    if (indexPath.row == 1) {
        
        TBCVideoViewController *controller = [[TBCVideoViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"视频"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];

    }
    if (indexPath.row == 2) {
        
        TBCReadingViewController *controller = [[TBCReadingViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"阅读"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];

    }
    if (indexPath.row == 3) {
        
        TBCWeatherViewController *controller = [[TBCWeatherViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"天气"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
        
    }
    if (indexPath.row == 4) {
        
        TBCSettingViewController *controller = [[TBCSettingViewController alloc] init];
        controller.title = [NSString stringWithFormat:@"设置"];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
        
        [menuController setRootController:navController animated:YES];
        
    }
    
        [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
